package server.core;

import server.Contained;
import server.Container;
import server.Valve;
import server.ValveContext;
import server.connector.http.HttpRequestImpl;
import server.connector.http.HttpResponseImpl;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;

public class SimpleWrapperValve implements Valve, Contained {
    //该阀所在的容器
    protected Container container;

    @Override
    public Container getContainer() {
        return container;
    }

    @Override
    public void setContainer(Container container) {
        this.container = container;
    }

    @Override
    public String getInfo() {
        return null;
    }

    @Override
    public void invoke(HttpRequestImpl request, HttpResponseImpl response, ValveContext context) throws IOException, ServletException {
        SimpleWrapper wrapper = (SimpleWrapper) getContainer();
        try {
            Servlet servlet = wrapper.allocate();
            servlet.service(request.getRequestFacade(), response.getResponseFacade());
        } catch (ServletException e) {

        }
    }
}
